package com.bys.admin.ai.mapper;

import java.util.*;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bys.admin.ai.controller.vo.ChatPageReqVO;
import com.bys.admin.ai.entity.Chat;
import com.bys.vo.PageVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.yulichang.base.MPJBaseMapper;
import org.apache.ibatis.annotations.Mapper;
import cn.hutool.core.util.StrUtil;

/**
 * AI Chat 对话 Mapper
 *
 * @author 系统管理员
 */
@Mapper
public interface ChatMapper extends MPJBaseMapper<Chat> {

    default Page<Chat> selectPage(ChatPageReqVO reqVO) {
        return selectPage(new Page<Chat>(reqVO.getPageNo(),reqVO.getPageSize()), new LambdaQueryWrapper<Chat>()
                .eq(Objects.nonNull(reqVO.getUserId()),Chat::getUserId, reqVO.getUserId())
                .eq(Objects.nonNull(reqVO.getTitle()),Chat::getTitle, reqVO.getTitle())
                .eq(Objects.nonNull(reqVO.getPinned()),Chat::getPinned, reqVO.getPinned())
                .eq(Objects.nonNull(reqVO.getRoleId()),Chat::getRoleId, reqVO.getRoleId())
                .eq(Objects.nonNull(reqVO.getKnowledgeId()),Chat::getKnowledgeId, reqVO.getKnowledgeId())
                .eq(Objects.nonNull(reqVO.getModelId()),Chat::getModelId, reqVO.getModelId())
                .eq(Objects.nonNull(reqVO.getSystemMessage()),Chat::getSystemMessage, reqVO.getSystemMessage())
                .eq(Objects.nonNull(reqVO.getTemperature()),Chat::getTemperature, reqVO.getTemperature())
                .eq(Objects.nonNull(reqVO.getMaxTokens()),Chat::getMaxTokens, reqVO.getMaxTokens())
                .eq(Objects.nonNull(reqVO.getMaxContexts()),Chat::getMaxContexts, reqVO.getMaxContexts())
        .orderByDesc(Chat::getCreateTime));
    }
}